
<template>
  <div class="login-container">
    <div class="login-box">
      <div style="padding: 50px 30px;background-color: white; margin-left: 100px; border-radius: 5px;box-shadow: 0 0 10px rgba(0,0,0,0.2)">
        <el-form ref="formRef" :rules="data.rules" :model="data.form" style="width: 300px">
          <div style="margin-bottom: 30px;font-size: 24px;text-align: center;color: #0742b1;font-weight: bold">登录鲜花后台管理系统</div>
          <el-form-item prop="username">
            <el-input size="large" v-model="data.form.username" placeholder="请输入账号" :prefix-icon="User"></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input size="large" v-model="data.form.password" placeholder="请输入密码" :prefix-icon="Lock" show-password></el-input>
          </el-form-item>
          <div style="margin-bottom: 20px">
            <el-button @click="login" type="primary" size="large" style="width: 100%">登 录</el-button>
          </div>
        </el-form>
        <div style="text-align: right">返回<a style="color: #0742b1;text-decoration: none" href="/">主页</a></div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.login-container{
  height: 100vh;
  overflow: hidden;
  background-image: url("@/assets/bbg.jpg");
  background-size:cover;
//background-position: ;
}
.login-box{
  width: 50%;
  height: 100%;
  display: flex;
  align-items: center;
  right: 0;
  position: absolute;
}
</style>

<script setup>
import {reactive, ref} from "vue";
import { User, Lock } from '@element-plus/icons-vue'
import request from "@/utils/request";
import {ElMessage} from "element-plus";
const data = reactive({
  form:{},
  rules:{
    username:[
      {required:true, message:'请输入账号',trigger:'blur'}
    ],
    password:[
      {required:true, message:'请输入密码',trigger:'blur'}
    ]
  }

})
const formRef = ref()

const login = () => {
  formRef.value.validate((valid) => {
    if(valid){
      request.post('/employee/login',data.form).then(res => {
        if(res.code === '0'){
          console.log(res.data)
          localStorage.setItem('xm-pro-employee',JSON.stringify(res.data))
          ElMessage.success("登录成功")
          window.location.href = '/Backend'
        }else{
          alert(res.msg)
        }
      })
    }
  })
}


</script>
